{include file="layout/header" title="分配权限" /}
<div class="view-body">
    {include file="layout/menu" /}
    <div class="view-product">
        <div class="company_identify">
            <div class="manage-head">
                <h6 class="padding-left manage-head-con">
                    分配权限
                </h6>
            </div>
            <form action="{:url('admin/Admin/auth')}" class="layui-form" method="post" style="margin: 20px 15px;">
                {volist name="rule" id="v"}
                <div class="layui-form-item">
                    <div class="layui-input-block" style="margin-left: 20px;">
                        <input name="rule_id[]" title="{$v.title}" type="checkbox" value="{$v.id}">
                            {volist name="v.son" id="vo"}
                            <input name="rule_id[]" title="{$vo.title}" type="checkbox" value="{$vo.id}">
                                {/volist}
                            </input>
                        </input>
                    </div>
                </div>
                {/volist}
                <div class="layui-form-item">
                    <div class="layui-input-block" style="margin-left: 20px;">
                        <input name="role_id" style="display: none;" type="text" value="{$role.id}">
                            <button class="layui-btn layui-btn-normal" type="submit">
                                提交
                            </button>
                            <button class="layui-btn layui-btn-warm" id="selectAll">
                                全选
                            </button>
                        </input>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    layui.use(['form','layer'], function(){
        var $ = layui.jquery;
        var layer = layui.layer;

        var rules = "{$role.rules}";
        var rule_id = rules.split(',');
        $(":checkbox").each(function(index){
            if(rule_id.indexOf($(this).val()) > -1){
              $(this).attr('checked',true);
              $(this).next().addClass("layui-form-checked");
            }
        });

        $("#selectAll").click(function(){
          if($(this).text() == "全选"){
            $(":checkbox").attr("checked",true);
            $(":checkbox").next().addClass("layui-form-checked");
            $(this).text("反选");
          }else{
            $(":checkbox").attr("checked",false);
            $(":checkbox").next().removeClass("layui-form-checked");
            $(this).text("全选");
          }
          return false;
        });

      });
</script>
{include file="layout/footer" /}
